<template>
  <h4>当前的求和为:{{sum}}</h4>
  <button @click="sum++ ">求和</button>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>薪资：{{ job.j1.salary }}K</h2>
  <button @click="name+='~' ">修改姓名</button>
  <button @click="age++ ">修改年龄</button>
  <button @click="job.j1.salary++ ">涨薪</button>
  <button @click="showRawPerson">输出最原始person</button>
  <button @click="addCar">给人添加车</button>
  <h3 v-show="person.car">座驾信息{{person.car}}</h3>

  <hr>
</template>

<script>
import {ref,toRef, reactive, toRefs,toRaw,markRaw} from 'vue'

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Demo',

  setup: function () {
    let sum = ref(0)
    let person = reactive({
      name: '张三',
      age: 18,
      job: {
        j1: {
          salary: 20
        }
      },

    })
    function showRawPerson(){
      const p =toRaw(person)
      console.log(p)
    }
    function addCar(){
      let car = {name:'奔驰',price:'40W'}
      person.car = markRaw(car);
    }

    // person =toRaw(person)
    // console.log(person)
    // person = markRaw(person)




    return {
      person,
      ...toRefs(person),
      sum,
      showRawPerson,
      addCar

    }
  }
}
</script>


